package com.example.leon.demo.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.leon.demo.R;
import com.example.leon.demo.RewriteParentControl.ReToast;
import com.example.leon.demo.adapter.FruitAdapter;
import com.example.leon.demo.common.BaseActivity;
import com.example.leon.demo.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wang.long on 2016/3/29.
 */
public class ListViewTest extends BaseActivity {

    private String[] data={"apple","banana","orange","watermelon","pear","grape","pineapple","starwberry","chery","mango","apple","banana","orange","watermelon","pear"};


    private List<Fruit> fruitList=new ArrayList<Fruit>();

    @Override
    protected void onCreate(Bundle saveInstanceState){
        super.onCreate(saveInstanceState);
        super.setContentView(R.layout.listviewtest);
        initData();
    }

    public void initData(){
        initFruit();
        FruitAdapter adapter=new FruitAdapter(ListViewTest.this,R.layout.fruit_item,fruitList);
        ListView listView=(ListView) findViewById(R.id.listview);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Fruit fruit=fruitList.get(position);
//                Toast toast=Toast.makeText(ListViewTest.this,fruit.getNmae(),Toast.LENGTH_SHORT);
//                    toast.show();
                ReToast.showToast(fruit.getNmae(),ListViewTest.this);





            }
        });
    }

    private void initFruit(){
        for(int i=0;i<data.length;i++){
            Fruit da = new Fruit(data[i],R.drawable.call_1);
            fruitList.add(da);
        }


    }




}
